package Workflow;

import java.util.concurrent.BlockingQueue;

import javax.swing.SwingWorker;

import Model.Candidate;
import Model.Report;

public class EvalTask extends SwingWorker<BlockingQueue<Candidate>, Candidate> {

	BlockingQueue<Report> inQueue;
	BlockingQueue<Candidate> outQueue_suitable;
	BlockingQueue<Candidate> outQueue_nonsuitable;
	private Report current_Report;
	
	public EvalTask (BlockingQueue<Report> inQ, BlockingQueue<Candidate> outQ_suitable, BlockingQueue<Candidate> outQ_nonsuitable){
		inQueue = inQ;
		outQueue_nonsuitable = outQ_nonsuitable;
		outQueue_suitable = outQ_suitable;
	}
	

	public void addCandidate_Suit(Candidate c){
		try {
			outQueue_suitable.put(c);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void addCandidate_Non_Suit(Candidate c){
		try {
			outQueue_nonsuitable.put(c);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void getCandidate(){
		try {
			current_Report = inQueue.take();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void Test(){
		getCandidate();
		if (current_Report.hr_tested && current_Report.pr_tested){
		
			if(current_Report.hr && current_Report.professional){
				current_Report.candidate.suitable = true;
				addCandidate_Suit(current_Report.candidate);
			}
			else {
				current_Report.candidate.suitable = false;
				addCandidate_Non_Suit(current_Report.candidate);
			}
			
		}
	}
	
	@Override
	protected BlockingQueue<Candidate> doInBackground() throws Exception {
		Test();
		System.out.println("Size: " + outQueue_suitable + " " + outQueue_nonsuitable);
		return null;
	}

}
